import { _decorator, Component, Node } from 'cc';
import { BaseView } from '../../../../../scripts/libs/rxjs/cc3/BaseView';
import { ReactiveProperty } from '../../../../../scripts/libs/rxjs/cc3/ReactiveProperty';
import { Vec3 } from 'cc';
import { v3 } from 'cc';
import { MergeASAP } from '../../../../../scripts/libs/rxjs/cc3/Merge';
import { UITransform } from 'cc';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('JointView')
@executeInEditMode
export class JointView extends BaseView {

    // private _p0 = ReactiveProperty.Create(v3());
    // public get p0(): Vec3 { return this._p0.value; }
    // public set p0(v: Vec3) { this._p0.value = v; }

    // private _p1 = ReactiveProperty.Create(v3());
    // public get p1(): Vec3 { return this._p1.value; }
    // public set p1(v: Vec3) { this._p1.value = v; }

    @property(Node)
    centerHNode: Node = null;

    @property(Node)
    centerVNode: Node = null;

    isV = ReactiveProperty.Create(false);

    useObserves() {
        return [
            // MergeASAP(this._p0, this._p1).subscribe(this.refresh.bind(this)),
            this.isV.subscribe(this.refresh.bind(this)),
        ];
    }

    center: Vec3 = v3();

    refresh() {
        // Vec3.lerp(this.center, this.p0, this.p1, .5);
        // this.node.setWorldPosition(this.center);

        if (this.isV.value) { // 竖着的
            this.centerHNode.active = false;
            this.centerVNode.active = true;
        } else { // 横着的
            this.centerHNode.active = true;
            this.centerVNode.active = false;
        }

        // this.lineNode.setPosition(0, 0, 0);

        // let rotZ = Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x);
        // this.lineNode.setRotationFromEuler(0, 0, rotZ * 180 / Math.PI);

        // let lineLen = Vec3.distance(this.p0, this.p1) - 110;
        // this.lineNode.getComponent(UITransform).width = lineLen;

        // this.circle0Node.setWorldPosition(this._p0.value);
        // this.circle1Node.setWorldPosition(this._p1.value);
    }



}

